//
//  FuncViewController.m
//  LibDemo
//
//  Created by Gikki Ares on 2020/9/5.
//

#import "CardListController.h"
#import <JsUtilitySdk/JsTableView.h>
#import <JsUtilitySdk/JsMenuView.h>
#import <JsUtilitySdk/JsRequestManager.h>
#import <JsUtilitySdk/JsDisplayManager.h>
#import <JsUtilitySdk/JsGeometryManager.h>
#import <JsUtilitySdk/JsRequestManager.h>
#import <JsUtilitySdk/JsColorManager.h>

@interface CardListController ()<
JsTableViewDelegate,
UITableViewDelegate,
UITableViewDataSource,
JsMenuViewDelegate
>
{
	JsTableView * mTableView;
	NSMutableArray * mMarr;
	JsMenuView * mMenuView;
}

@end

@implementation CardListController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
	
	self.view.backgroundColor = [JsColorManager morandi_orange];
	
//	marr = @[@""];
	[self setupUi];
	self.edgesForExtendedLayout = UIRectEdgeNone;

	mMenuView = [[JsMenuView alloc]initWithFrame:CGRectMake(0, 0, JsGeometryManager.screenWidth, 300)];
	JsDisplayStyle * style = [JsDisplayStyle defaulStyle];
	style.mb_isHasShadow = NO;
	style.displayPosition = JsDisplayPositionBottom;
	style.mb_isMaskCancellable = NO;
	[mMenuView displayInView:self.view withDisplayStyle:style undisplayCompletionHandler:nil];
	mMenuView.delegate = self;
	mMarr = [@[@"0",@"1",@"2"] mutableCopy];
}

- (void)requestFirstPageIsEmpty:(BOOL)isEmpty {
	if(isEmpty) {
		[mMarr removeAllObjects];
		[mTableView reloadData];
		[mTableView finishRefreshWithIsSuccess:YES dataCount:0];
	}
	else {
		
	}
}

- (void)setupUi {
	if(!mTableView) {
		mTableView = [[JsTableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 400)];
		mTableView.jsDelegate = self;
		[self.view addSubview:mTableView];
	}
}

- (void)viewDidLayoutSubviews {
	[super viewDidLayoutSubviews];
}

# pragma mark 4 Delegate
- (JsTableViewStyle *)jsTableViewSetStyle:(JsTableView *)tableView {
	JsTableViewStyle * style = [JsTableViewStyle defaultStyle];
	style.mColor_tableViewBackground = [JsColorManager morandi_lightGray];
	style.mColor_defaultNoDataViewBackground = [JsColorManager morandi_lightGray];
	return style;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
	if(!cell) {
		cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
	}
	cell.backgroundColor = [UIColor whiteColor];
	cell.textLabel.text = [NSString stringWithFormat:@"%d",(int)indexPath.row];
	cell.textLabel.textColor = [UIColor blackColor];
	return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return mMarr.count;
}


#pragma mark MenuView
- (NSArray<JsMenuItemVm *> *)jsMenuViewSetDatasource:(JsMenuView *)view {
	return @[
		[[JsMenuItemVm alloc] initWithTitle:@"清空"],
		[[JsMenuItemVm alloc] initWithTitle:@"增加"],
		[[JsMenuItemVm alloc] initWithTitle:@"加载第0页-空"]
	];
}

- (void)jsMenuView:(JsMenuView *)view clickMenuAtIndex:(int)index vm:(JsMenuItemVm *)vm {
	switch(index) {
		case 0:{
			[mMarr removeAllObjects];
			[mTableView reloadData];
			break;
		}
		case 1:{
			[mMarr removeAllObjects];
			[mTableView reloadData];
			break;
		}
		case 2:{
			[self requestFirstPageIsEmpty:YES];
			break;
		}
	}
	
}

@end
